<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<%@include file="../../public/commonJs.jsp" %>
<%@include file="../../public/commonCss.jsp" %>
<div class="layui-form" style="padding: 20px">
    <input type="hidden" name="sortOrder" value="${work.sortOrder}">
    <blockquote class="layui-elem-quote">上级信息</blockquote>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">上一级编号:</label>
            <div class="layui-input-inline">
                <input name="parentId" id="parentId" type="text" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">上一级名称:</label>
            <div class="layui-input-inline">
                <input name="stemp" type="text" id="parentName" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
                <button class="layui-btn layui-btn-primary" onclick="closeLayer()">取消</button>
            </div>
        </div>
    </div>
    <blockquote class="layui-elem-quote">基本信息</blockquote>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"> <span class="fontRed">*</span>编号：</label>
            <div class="layui-input-inline">
                <input name="id" type="text" class="layui-input" value="${work.id}" readonly>
            </div>
            <div class="layui-form-mid layui-word-aux">编号是自动生成的,不用填写</div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> <span class="fontRed">*</span>选择车型:</label>
        <div class="layui-input-block">
            <c:forEach var="codeData" items="${codeDatas}">
                <input type="checkbox"
                       name="trainTypeNames[${codeData.itemValue}]" title="${codeData.itemText}"
                       value="${codeData.itemText}">
            </c:forEach>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><span class="fontRed">*</span>名称：</label>
            <div class="layui-input-inline">
                <input name="name" type="text" class="layui-input" placeholder="请输入名称" lay-verify="required">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">目录或功能:</label>
            <div class="layui-input-inline">
                <input type="radio" name="isCatalog" lay-filter='r1' value="0" title="目录"/>
                <input type="radio" name="isCatalog" lay-filter='r1' value="1" title="功能" checked/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">提示信息：</label>
            <div class="layui-input-inline">
                <input name="remindInfo" type="text" class="layui-input"
                       value="${work.remindInfo}">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><span class="fontRed">*</span>NFC数量：</label>
            <div class="layui-input-inline">
                <input type="number" class="layui-input" value="${work.nfcNum}" disabled/>
            </div>
            <div class="layui-form-mid layui-word-aux">目录下此处为只读</div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><span class="fontRed">*</span>拍照数量：</label>
            <div class="layui-input-inline">
                <input type="number" class="layui-input" value="${work.photoNum}" disabled/>
            </div>
            <div class="layui-form-mid layui-word-aux">目录下此处为只读</div>
        </div>
    </div>
    <div class="layui-form-item cc">
        <label class="layui-form-label"><span class="fontRed">*</span>工序分类：</label>
        <div class="layui-input-block">
            <input type="radio" name="workType" value="1" lay-filter='r2' title="拍照" checked/>
            <input type="radio" name="workType" value="0" lay-filter='r2' title="NFC"/>
            <input type="radio" name="workType" value="2" lay-filter='r2' title="物品领取"/>
            <input type="radio" name="workType" value="3" lay-filter='r2' title="物品归还"/>
        </div>
    </div>
    <div class="layui-form-item cc">
        <div class="layui-inline nfcPlace">
            <label class="layui-form-label"><span class="fontRed">*</span>NFC位置：</label>
            <div class="layui-input-inline">
                <select name="nfcPlace">
                    <option value="">--请选择nfc位置--</option>
                    <c:forEach var="nfcPlace" items="${nfcPlaces}">
                        <option value="${nfcPlace.itemValue}">${nfcPlace.itemText}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>
    <blockquote class="layui-elem-quote">评分系统</blockquote>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 150px"><span class="fontRed">*</span>提前完成扣分分值：</label>
            <div class="layui-input-inline">
                <input name="numScoreOne" type="number" value="${work.numScoreOne}" class="layui-input"
                       lay-verify="score">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 150px"><span class="fontRed">*</span>未完成扣分分值：</label>
            <div class="layui-input-inline">
                <input name="numLimitOne" type="number" value="${work.numLimitOne}" class="layui-input"
                       lay-verify="score">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 150px"><span class="fontRed">*</span>扣分时间区间：</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input name="timeLimitOne" type="number" value="${work.timeLimitOne}" class="layui-input"
                       lay-verify="score">
            </div>
            <div class="layui-form-mid">~</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input name="timeLimitTwo" type="number" value="${work.timeLimitTwo}" class="layui-input"
                       lay-verify="score">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 150px"><span class="fontRed">*</span>扣分时间分值：</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input name="timeLimitOne" type="number" value="${work.timeLimitOne}" class="layui-input"
                       lay-verify="score">
            </div>
            <div class="layui-form-mid">~</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input name="timeScoreTwo" type="number" value="${work.timeScoreTwo}" class="layui-input"
                       lay-verify="score">
            </div>
            <div class="layui-form-mid">~</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input name="timeScoreThree" type="number" value="${work.timeScoreThree}"
                       class="layui-input" lay-verify="score" style="width:100px"/>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    $(function () {
        var isCatalog = '${work.isCatalog}'
        $("#parentId").val(parent.vm.$model.selectNodeId);
        $("#parentName").val(parent.vm.$model.selectNodeName);
        $(".nfcPlace").hide();
    });

    var form = layui.form();
    form.on('radio(r1)', function (data) {
        console.log(data.value); //被点击的radio的value值
        if (data.value == '0') {
            $('.cc').hide();
        } else {
            $('.cc').show();
        }
    });
    form.on('radio(r2)', function (data) {
        console.log(data.value); //被点击的radio的value值
        if (data.value == '0') {
            $(".nfcPlace").show();
        } else {
            $(".nfcPlace").hide();
        }
    });
    //自定义验证规则
    form.verify({
        score: function (value) {
            if (value.length > 2) {
                return '分数数应为0~99内';
            }
        }
    });
    //监听提交
    form.on('submit(demo1)', function (data) {
        console.log(data.field);
        var newNode = {
            id: data.field.id,
            name: data.field.name,
            parentId: data.field.parentId
        }
        //这里执行ajax提交
        $.ajax({
            type: 'post',
            url: '${ctx}/workController/saveWork.action',
            data: data.field,
            dataType: "json",
            timeout: 10000,
            beforeSend: function () {
                parent.layer.msg('正在保存数据...', {
                    icon: 16,
                    shade: 0.01
                });
            },
            success: function (data) {
                if (data.code == 0) {
                    var selectNode = parent.zTreeObj.getSelectedNodes();
                    parent.layer.closeAll();
                    parent.layer.msg('保存成功.', {icon: 1});
                    parent.zTreeObj.addNodes(selectNode[0], newNode);
                    parent.addWork();
                } else {
                    parent.layer.msg('操作失败，请重试.', {icon: 2});
                }
            }
        });
        return false;
    });
    form.render();

    //关闭对话框
    function closeLayer() {
        parent.setIframeSrc("");
    }
</script>